with open('example.txt') as f: if 'blabla' in f.read(): print("true")
import mmap with open('example.txt') as f: s = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) if s.find('blabla') != -1: print('true')